package edu.zju.gis.dbfg.queryserver.model;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

@Getter
@Setter
@ToString
@JsonInclude(JsonInclude.Include.NON_NULL)
public class SearchResult implements Serializable {
    private int pageSize = 200;
    private Number curresult;
    private Number total;
    private Double time;
    private Integer entitytotal;
    private String bound;
    private String cluster;
    private String scrollId;
    private List<Map<String, Object>> features;

    public SearchResult getDataPage(int pageNo) {
        if (pageNo > 0 && this.pageSize > 0) {
            SearchResult subitem = new SearchResult();
            subitem.pageSize = this.pageSize;
            subitem.curresult = this.curresult;
            subitem.total = this.total;
            subitem.time = this.time;
            subitem.entitytotal = this.entitytotal;
            subitem.bound = this.bound;
            subitem.cluster = this.cluster;
            subitem.scrollId = this.scrollId;
            int offset = (pageNo - 1) * this.pageSize;
            subitem.features = this.features.subList(offset, this.pageSize);
            return subitem;
        } else {
            System.out.println("Page ERROR.");
            return null;
        }
    }

    public SearchResult getDataPage(int pageNo, int pageSize) {
        this.pageSize = pageSize;
        return getDataPage(pageNo);
    }
}
